/***************************************
 * 说明：本文件主要列举第2章文中所实现的例题
 * *************************************/
#include <iostream>
using namespace std;

/******************************************
 * 例子2.1：用类来实现输入和输出时间（时:分:秒）
 * ****************************************/
class Time {
public:
    int hour;
    int minute;
    int second;
};

void example1()
{
    Time time;
    cin >> time.hour;
    cin >> time.minute;
    cin >> time.second;
    cout << time.hour << ":" << time.minute << ":" << time.second << endl;
}

/********************************************************
 * 例子2.2：用上面的类实现多个实例，分别输入输出各个对象的时间
 * ******************************************************/
void example2()
{
    Time time;
    cin >> time.hour;
    cin >> time.minute;
    cin >> time.second;
    cout << time.hour << ":" << time.minute << ":" << time.second << endl;
    Time time1;
    cin >> time1.hour;
    cin >> time1.minute;
    cin >> time1.second;
    cout << time1.hour << ":" << time1.minute << ":" << time1.second << endl;
}

// 使用函数对输入输出进行封装
void set_time(Time& time)
{
    cin >> time.hour;
    cin >> time.minute;
    cin>> time.second;
}

void show_time(Time& time)
{
    cout << time.hour << ":" << time.minute << ":" << time.second << endl;
}
void example22()
{
    Time t1;
    set_time(t1);
    show_time(t1);
    Time t2;
    set_time(t2);
    show_time(t2);
}
/********************************************************
 * 例子2.3：将例2.2使用类的成员函数实现
 * ******************************************************/
class Time23 {
public:
    void set_time();
    void show_time();
public:
    int hour;
    int minute;
    int second;
};
void Time23::set_time()
{
    cin >> hour;
    cin >> minute;
    cin >> second;
}
void Time23::show_time()
{
    cout << hour << ":" << minute << ":" << second << endl;
}

void example3()
{
    Time23 time1;
    time1.set_time();
    time1.show_time();
}
/********************************************************
 * 例子2.4：定义一个数组，找出数组中的最大元素
 * ******************************************************/
class Arry {
public:
    void set_item();
    void max_item();
    void show_max();
public:
    int arry[5];
    int max;
};
void Arry::set_item()
{
    for (int i = 0; i<5; i++) {
        cin >> arry[i];
    }
}
void Arry::max_item()
{
    max = arry[0];
    for (int i = 0; i<5; i++) {
        if (arry[i] > max) {
            max = arry[i];
        }
    }
}
void Arry::show_max()
{
    cout << max << endl;;
}
void example4()
{
    Arry arr;
    arr.set_item();
    arr.max_item();
    arr.show_max();
}

int main()
{
    example4();
}